From 68d78231970b8c1f62c60b05682866c5e8889093 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Juan=20Hern=C3=A1ndez?= Date: Thu, 8 Sep 2016 20:35:13 -0400 Subject: [PATCH] Remove fs::canonicalize in walk_tree fix. * Remove ConfiFile struct, it is not needed without the fs::canonicalize call. * Don't check if the file is in the stash when walking the tree, without "canonicalization" it is not necessary. --- src/cargo/util/config.rs | 44 ++++++++-------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 70dadbd98..2f207d86e 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -22,30 +22,6 @@ use util::toml as cargo_toml; use self::ConfigValue as CV; -#[derive(PartialEq, Eq, Hash)] -struct ConfigFile { - path: Option, -} - -impl ConfigFile { - pub fn new(path: PathBuf) -> ConfigFile { - let canonical = match fs::canonicalize(path) { - Ok(p) => Some(p), - Err(_) => None, - }; - - ConfigFile { path: canonical } - } - - pub fn exist(&self) -> bool { - self.path.is_some() - } - - pub fn as_path_buf(&self) -> Option { - self.path.clone() - } -} - pub struct Config { home_path: Filesystem, shell: RefCell, @@ -700,15 +676,14 @@ fn walk_tree(pwd: &Path, mut walk: F) -> CargoResult<()> where F: FnMut(File, &Path) -> CargoResult<()> { let mut current = pwd; - let mut stash: HashSet = HashSet::new(); + let mut stash: HashSet = HashSet::new(); loop { - let possible = ConfigFile::new(current.join(".cargo").join("config")); - if possible.exist() && stash.get(&possible).is_none() { - let name = possible.as_path_buf().unwrap(); - let file = try!(File::open(&name)); + let possible = current.join(".cargo").join("config"); + if fs::metadata(&possible).is_ok() { + let file = try!(File::open(&possible)); - try!(walk(file, &name)); + try!(walk(file, &possible)); stash.insert(possible); } @@ -726,11 +701,10 @@ fn walk_tree(pwd: &Path, mut walk: F) -> CargoResult<()> human("Cargo couldn't find your home directory. \ This probably means that $HOME was not set.") })); - let config = ConfigFile::new(home.join("config")); - if config.exist() && stash.get(&config).is_none() { - let name = config.as_path_buf().unwrap(); - let file = try!(File::open(&name)); - try!(walk(file, &name)); + let config = home.join("config"); + if !stash.contains(&config) && fs::metadata(&config).is_ok() { + let file = try!(File::open(&config)); + try!(walk(file, &config)); } Ok(()) -- 2.30.2